﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.UI.WebControls;
using Domain.Interface;
using Domain.Model;
using Domain.Model.Domain_MoBan_Model;
using Newtonsoft.Json;
using WebAPI.Attributes;

namespace WebAPI.Controllers
{
    public class KeShiController : ApiController
    {
        #region 科室
        public IKeShi _KeShi { set; get; }
        /// <summary>
        /// 添加科室
        /// </summary>
        /// <param name="ksmc">科室名称</param>
        [HttpGet]
        public void AddKeShi(string ksmc)
        {
            _KeShi.SaveKeShi(ksmc);
        }
        /// <summary>
        /// 更新科室
        /// </summary>
        /// <param name="ksid"></param>
        /// <param name="ksmc"></param>
        [HttpGet]
        public void UpdateKeShi(int ksid, string ksmc)
        {
            _KeShi.SaveKeShi(ksid, ksmc);
        }
        /// <summary>
        /// 获取所有科室
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public List<Domain_KeShi> GetAllKeShis()
        {
            var str = _KeShi.GetAllKeShiList(1, 1, 1);
            return JsonConvert.DeserializeObject<List<Domain_KeShi>>(str);
        }
        /// <summary>
        /// 删除科室
        /// </summary>
        /// <param name="ksid"></param>
        [HttpGet]
        public void DelKeShi(int ksid)
        {
            _KeShi.DelKeShiById(ksid);
        }
        #endregion
        #region 职务
        #region 新版

        [HttpPost]
        public Domain_ZhiWu SaveZhiWu(dynamic model)
        {
            var Domainmodel = new Domain_ZhiWu();
            Domainmodel = JsonConvert.DeserializeObject<Domain_ZhiWu>(_KeShi.SaveZhiWu(model.zwmc.ToString(), int.Parse(model.pid.ToString())));
            return Domainmodel;
        }
        [HttpPost]
        public Domain_ZhiWu UpdateZhiWu(dynamic model)
        {
            var Domainmodel = new Domain_ZhiWu();
            Domainmodel = JsonConvert.DeserializeObject<Domain_ZhiWu>(_KeShi.UpdateZhiWu(int.Parse(model.zwid.ToString()), model.zwmc.ToString(), int.Parse(model.pid.ToString())));
            return Domainmodel;
        }
        [HttpGet]
        public void DelZhiWu(int zwid)
        {
            _KeShi.DelZhiWuById(zwid);
        }

        [HttpPost]
        public List<Domain_ZhiWu> GetZhiWus()
        {
            var lst = new List<Domain_ZhiWu>();
            lst = JsonConvert.DeserializeObject<List<Domain_ZhiWu>>(_KeShi.GetZhiWus());
            return lst;
        }
        [HttpPost]
        public void ZhiWuRelationKeShi(dynamic model)
        {
            _KeShi.ZhiWuRelationKeShi(int.Parse(model.ksid.ToString()), int.Parse(model.zwid.ToString()));
        }
        [HttpPost]
        public void KeShiZhiWu(dynamic model)
        {
            _KeShi.KeShiZhiWu(int.Parse(model.ksid.ToString()));
        }
        [HttpPost]
        public void DelKeShiZhiWu(dynamic model)
        {
            _KeShi.DelKeShiZhiWu(int.Parse(model.ksid.ToString()), int.Parse(model.zwid.ToString()));
        }
        [HttpPost]
        public void KaoHeBiaoRelationZhiWu(dynamic model)
        {
            _KeShi.KaoHeBiaoRelationZhiWu(int.Parse(model.ksid.ToString()), int.Parse(model.zwid.ToString()), int.Parse(model.khbid.ToString()));
        }
        [HttpPost]
        public void DelKaoHeBiaoRelationZhiWu(dynamic model)
        {
            _KeShi.DelKaoHeBiaoRelationZhiWu(int.Parse(model.ksid.ToString()), int.Parse(model.zwid.ToString()), int.Parse(model.khbid.ToString()));
        }

        [HttpPost]
        public List<Domain_MoBan_Main> GetZhiWuKaoHeBiao(dynamic model)
        {
            return _KeShi.GetZhiWuKaoHeBiao(int.Parse(model.ksid.ToString()), int.Parse(model.zwid.ToString()));
        }
        [HttpPost]
        public void ZhiWuRelationPower(dynamic model)
        {
            _KeShi.ZhiWuRelationPower(int.Parse(model.ksid.ToString()), int.Parse(model.zwid.ToString()), model.power.ToString());
        }
        #endregion

        [HttpGet]
        public List<Domain_ZhiWu> GetKeShiZhiWus(int ksid)
        {
            var str = _KeShi.GetKeShiNeiZhiWu(ksid);
            return JsonConvert.DeserializeObject<List<Domain_ZhiWu>>(str);
        }

        [HttpGet]
        public List<Domain_ZhiWu> GetKeShiZhiWusOption(int ksid)
        {
            var str = _KeShi.GetKeShiZhiWusOption(ksid);
            return JsonConvert.DeserializeObject<List<Domain_ZhiWu>>(str);
        }
        [HttpGet]
        public void AddZhiWu(int ksid, string zwmc, int pid, int gzjhid, int jxkhid)
        {
            _KeShi.SaveZhiWu(ksid, zwmc, pid, gzjhid, jxkhid);
        }
        [HttpGet]
        public void EditZhiWu(int ksid, int zwid, string zwmc, int pid, int gzjhid, int jxkhid)
        {
            _KeShi.SaveZhiWu(ksid, zwid, zwmc, pid, gzjhid, jxkhid);
        }
        //[HttpGet]
        //public void DelZhiWu(int zwid)
        //{
        //    _KeShi.DelZhiWuById(zwid);
        //}

        [HttpGet]
        public List<Domain_ZhiWu> GetOneLevelZhiWu(int ksid)
        {
            string str = _KeShi.GetKeShiZhiWuOneLevel(ksid);
            return JsonConvert.DeserializeObject<List<Domain_ZhiWu>>(str);
        }

        [HttpGet, WriteFileExceptionAspect]
        public List<Domain_PowerTree> GetPowerTrees()
        {
            string str = _KeShi.GetQuanXians();
            return JsonConvert.DeserializeObject<List<Domain_PowerTree>>(str);
        }
        /// <summary>
        /// 保存职务权限
        /// </summary>
        /// <param name="zwid"></param>
        /// <param name="ptmc"></param>
        [HttpPost, WriteFileExceptionAspect]
        public void SaveZhiWuPowerTrees(dynamic obj)
        {
            _KeShi.SaveQuanXian(int.Parse(obj.ksid.ToString()), int.Parse(obj.zwid.ToString()), obj.ptmc.ToString());
        }
        #endregion
    }
}
